package com.pxst.bank.controller;

import com.pxst.annotations.LogOperate;
import com.pxst.bank.entity.SysAvailableBankEntity;
import com.pxst.bank.req.BankDetailReq;
import com.pxst.bank.req.BankDetailSearchReq;
import com.pxst.bank.req.BankSearchReq;
import com.pxst.bank.req.BankUpdateReq;
import com.pxst.bank.resp.*;
import com.pxst.bank.service.SysAvailableBankService;
import com.pxst.bank.service.SysBankCardGroupService;
import com.pxst.entity.Insert;
import com.pxst.entity.Update;
import com.pxst.resp.ApiResp;
import com.pxst.sys.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.swing.*;
import java.util.List;

/**
 * @author zarke
 * @description 银行账户管理-银行相关接口
 * @since 2023-09-26 11:10:14
 */
@RestController
@RequestMapping("/api/bank")
@Api(tags = "银行相关接口")
@Slf4j
public class SysAvailableBankController {


    @Autowired
    private SysAvailableBankService sysAvailableBankService;
    @Autowired
    private UserService userService;

    /*//  需要单独写一个分页？
    @GetMapping("/list")
    @ApiOperation("银行-列表 分页")
    public ApiResp<PageResp<BankSearchResp>> getBankInfoList(BasePageRsp basePageRsp) {
        log.info("basePageRsp:{}",basePageRsp);
        return sysAvailableBankService.getBankInfoList(basePageRsp);
    }*/

    @GetMapping("/bankSearch")
    @ApiOperation("银行-搜索")
    public ApiResp<List<BankSearchResp>> getBankListByCondition(BankSearchReq bankSearchReq) {
        log.info("银行-搜索传入的条件：{}", bankSearchReq);
        ApiResp<List<BankSearchResp>> bankList = sysAvailableBankService.getBankListByCondition(bankSearchReq);
        log.info("查询到的银行列表 bankList :{}", bankList);
        return bankList;
    }

    @PutMapping("/{id}")
    @ApiOperation("银行-编辑")
    @LogOperate(operate = "银行编辑", service = SysAvailableBankService.class, type = "edit")
    public ApiResp<Spring> updateBankById(@PathVariable Long id, @RequestBody @Validated(Update.class) BankUpdateReq bankUpdateReq) {
        log.info("update id:{},bankReq:{}", id, bankUpdateReq);
        log.info("修改后的银行数据:{}", sysAvailableBankService.updateBankById(id, bankUpdateReq));
        return sysAvailableBankService.updateBankById(id, bankUpdateReq);
    }

    @PostMapping("/create")
    @ApiOperation("银行-新增")
    @LogOperate(operate = "银行新增", service = SysAvailableBankService.class, type = "add")
    public ApiResp<String> create(@RequestBody @Validated(Insert.class) SysAvailableBankEntity sysAvailableBankEntity) {
        log.info("新增的银行信息:{}", sysAvailableBankEntity);
        return sysAvailableBankService.create(sysAvailableBankEntity);
    }

    @GetMapping("/bankDetails")
    @ApiOperation("銀行-详情")
    public ApiResp<List<BankDetailResp>> getBankById(BankDetailReq bankDetailReq) {
        log.info("查询银行详情请求类信息:{}", bankDetailReq);
        return sysAvailableBankService.getBankById(bankDetailReq);
    }

    @GetMapping("/simple")
    @ApiOperation(value = "可用银行信息")
    public ApiResp<List<AvailableBankListResp>> getBankList() {
        return sysAvailableBankService.getAvailableBank();
    }

    @GetMapping("/bankDetails/search")
    @ApiOperation("银行-详情-搜索（条件查询）")
    public ApiResp<List<BankDetailResp>> getBankLogByCondition(BankDetailSearchReq bankDetailSearchReq) {
        return sysAvailableBankService.getBankLogByCondition(bankDetailSearchReq);
    }
}
